﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;
using Microsoft.Win32;

namespace PCDoctor.ScanParameters
{
    class GameModeParameter: ServicesScanParameter
    {
        public GameModeParameter(string name, string path, string value, Int64 problemId) :
            base(name, path, value, problemId)
        {
            Kind = ScanFixerKinds.Gaming;
        }

        public override FixationResult Fix()
        {
            FixedProblems = 0;
            if (this.Result == ScanResult.OK)
            {
                FixResult = FixationResult.NoNeedToFix;
                return FixationResult.NoNeedToFix;
            }
            FixedProblems = 0;
            FixResult = FixationResult.DontBegin;
            foreach (KeyValuePair<string, string> kv in PathsValues)
            {
                try
                {
                    ServiceController sc = new ServiceController(kv.Key);
                    if (sc.CanStop && sc.Status == ServiceControllerStatus.Running)
                    {
                        FixedProblems++;
                        sc.Stop();
                    }
                }
                catch (Exception)
                {
                    FixedProblems--;
                    FixResult = FixationResult.Error;
                }
            }
            if (FixResult == FixationResult.DontBegin)
            {
                FixResult = FixationResult.Fixed;
            }
            return FixResult;
        }
    }
}
